package show.lmm.demo.springboot_aot.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * 文件操作工具类
 */
public class FileUtils {

    /**
     * 读取文件所有内容
     *
     * @param inputStream 文件流
     * @return String 文件内容
     */
    public static List<String> readAllLines(InputStream inputStream) {
        List<String> lineStrs = new ArrayList<>();
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
        String line;
        try {
            while ((line = br.readLine()) != null) {
                lineStrs.add(line);
            }
        } catch (IOException ignored) {

        }
        return lineStrs;
    }

    /**
     * 读取文件所有内容
     *
     * @param inputStream 文件流
     * @return String 文件内容
     */
    public static String readAllText(InputStream inputStream) {
        return String.join("\r\n", readAllLines(inputStream));
    }
}
